package sealte.wdgf.system.listener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EAIServerContextListener implements ServletContextListener {
	
	//执行顺序1
	static{
		setProperties();
	}
	
	//执行顺序2
	private static Logger logger = LoggerFactory.getLogger(EAIServerContextListener.class);
	
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		ServletContext application = sce.getServletContext();
		application.removeAttribute("ROM");
		logger.info("EAIServerContextListener stop working!");
	}
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		logger.info("EAIServerContextListener begin working!");
		Map<String,List<HttpServletRequest>> reqObjMap = new HashMap<String,List<HttpServletRequest>>();
		ServletContext application = sce.getServletContext();
		application.setAttribute("ROM", reqObjMap);
	}
	
	private static void setProperties(){
		//为log4j.properties配置文件的变量${LOG_DIR}赋值
		String webInfPath = EAIServerContextListener.class.getResource("").getPath()
				+"../../../../../";
		System.setProperty("LOG_DIR", webInfPath+"logs");
	}
	
}
